# $Id: PKGBUILD 84403 2013-02-18 13:25:20Z schiv $
# Maintainer: Ray Rashif <schiv@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Geoffroy Carrier <geoffroy.carrier@koon.fr>
# Contributor: Thomas Jost <thomas.jost@gmail.com>

pkgname=subdownloader
pkgver=2.0.18
pkgrel=1
pkgdesc="Automatic download/upload of subtitles using fast hashing"
arch=('any')
url="http://www.subdownloader.net/"
license=('GPL3')
depends=('imdbpy' 'kaa-metadata' 'python2-pyqt')
makedepends=('icu')
options=('!emptydirs')
install=$pkgname.install
source=("http://launchpad.net/$pkgname/trunk/$pkgver/+download/${pkgname}_$pkgver.orig.tar.gz")
md5sums=('11dbc455f542b68e96e2cc539deb3f8f')

build() {
  cd "$srcdir/$pkgname-$pkgver"

  # python2 fix
  for file in $(find . -name '*.py' -print); do
    sed -i 's_^#!.*/usr/bin/python_#!/usr/bin/python2_' $file
    sed -i 's_^#!.*/usr/bin/env.*python_#!/usr/bin/env python2_' $file
  done
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  # prepare dirs
  install -d "$pkgdir/usr/share/$pkgname" \
    "$pkgdir/usr/bin" \
    "$pkgdir/usr/share/man/man1/"

  # manuals
  gzip subdownloader.1
  install -D subdownloader.1.gz "$pkgdir/usr/share/man/man1/"

  # freedesktop.org
  install -D -m644 subdownloader.desktop \
    "$pkgdir/usr/share/applications/subdownloader.desktop"
  rm subdownloader.1.gz subdownloader.desktop

  # runtime and executables
  cp -a * "$pkgdir/usr/share/$pkgname/"
  chmod 755 "$pkgdir/usr/share/$pkgname/run.py"
  ln -s "/usr/share/$pkgname/run.py" \
    "$pkgdir/usr/bin/subdownloader"

  install -D -m644 gui/images/subdownloader.png \
    "$pkgdir/usr/share/pixmaps/subdownloader.png"

  # unnecessary directories
  cd "$pkgdir/usr/share/$pkgname"
  rm -r distribution
}

# vim:set ts=2 sw=2 et:
